<div class="row">
  <div class="col-sm-3">
    <%= cip_category_treenav Cip::Category.hash_tree %>
  </div>
  <div class="col-sm-9">
    <h3 class="page-header">
      <%= @category && @category.title %> <small> <%= link_to "新建页面", new_cip_admin_category_page_path(@category) if @category && @category.editable %> <%= link_to "编辑分类", edit_cip_admin_category_path(@category) %> <%= link_to "新建子分类", new_cip_admin_category_category_path(@category) if superuser? %> </small>
    </h3>
    <% @pages = @pages.where(disabled: [nil, false]) unless superuser? %>
    <%= index_for @pages, class: 'table table-striped table-hover datatable', data: { reorder: true } do |i| %>
      <%= i.attribute :position %>
      <%= i.attribute :title %>
      <%= i.attribute :author %>
      <%= i.attribute :created_at, format: :long %>

      <%= i.actions do |a| %>
        <%= a.action_link :edit, url: edit_cip_admin_page_path(i.object) %>
        <%= a.action_link :destroy, url: cip_admin_page_path(i.object) if @category && @category.editable %>
      <% end %>
    <% end %>
  </div>
</div>

<script type="text/javascript">
  $(".table.datatable").on("row-reordered.dt", function(event, details) {
    if (details.length === 0) return;
    $.ajax({
      method: 'POST',
      url: '<%= reorder_cip_admin_category_pages_path(@category) %>',
      data: { positions: $.map(details, function(detail) { return { new_data: detail.newData, old_data: detail.oldData } }) }
    });
  });
</script>
